package com.example.dao;

import com.example.entity.Company;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CompanyRepository extends JpaRepository<Company,Long>{

    /**
     * 根据公司名称查询公司
     * @param name
     * @return
     */
    Company findByName(String name);

    @Query("SELECT DISTINCT c FROM Company c LEFT JOIN FETCH c.employees WHERE c.isOperating = true")
    List<Company> findByIsOperatingTrueWithEmployees();
}